extends Node
class_name Realm

# 境界定义
enum RealmLevel {
	QI_REFINING_1, QI_REFINING_2, QI_REFINING_3, QI_REFINING_4, QI_REFINING_5,
	QI_REFINING_6, QI_REFINING_7, QI_REFINING_8, QI_REFINING_9, QI_REFINING_10,
	
	FOUNDATION_1, FOUNDATION_2, FOUNDATION_3, FOUNDATION_4, FOUNDATION_5,
	FOUNDATION_6, FOUNDATION_7, FOUNDATION_8, FOUNDATION_9, FOUNDATION_10,
	
	GOLDEN_CORE_1, GOLDEN_CORE_2, GOLDEN_CORE_3, GOLDEN_CORE_4, GOLDEN_CORE_5,
	GOLDEN_CORE_6, GOLDEN_CORE_7, GOLDEN_CORE_8, GOLDEN_CORE_9, GOLDEN_CORE_10,
	
	NASCENT_SOUL_1, NASCENT_SOUL_2, NASCENT_SOUL_3, NASCENT_SOUL_4, NASCENT_SOUL_5,
	NASCENT_SOUL_6, NASCENT_SOUL_7, NASCENT_SOUL_8, NASCENT_SOUL_9, NASCENT_SOUL_10,
	
	SPIRIT_TRANSFORMATION_1, SPIRIT_TRANSFORMATION_2, SPIRIT_TRANSFORMATION_3, SPIRIT_TRANSFORMATION_4, SPIRIT_TRANSFORMATION_5,
	SPIRIT_TRANSFORMATION_6, SPIRIT_TRANSFORMATION_7, SPIRIT_TRANSFORMATION_8, SPIRIT_TRANSFORMATION_9, SPIRIT_TRANSFORMATION_10,
	
	VOID_REFINEMENT_1, VOID_REFINEMENT_2, VOID_REFINEMENT_3, VOID_REFINEMENT_4, VOID_REFINEMENT_5,
	VOID_REFINEMENT_6, VOID_REFINEMENT_7, VOID_REFINEMENT_8, VOID_REFINEMENT_9, VOID_REFINEMENT_10,
	
	BODY_INTEGRATION_1, BODY_INTEGRATION_2, BODY_INTEGRATION_3, BODY_INTEGRATION_4, BODY_INTEGRATION_5,
	BODY_INTEGRATION_6, BODY_INTEGRATION_7, BODY_INTEGRATION_8, BODY_INTEGRATION_9, BODY_INTEGRATION_10,
	
	MAHAYANA_1, MAHAYANA_2, MAHAYANA_3, MAHAYANA_4, MAHAYANA_5,
	MAHAYANA_6, MAHAYANA_7, MAHAYANA_8, MAHAYANA_9, MAHAYANA_10,
	
	ASCENSION
}

# 境界配置 - 每个境界的基础灵气需求
const REALM_CONFIG = {
	# 练气期
	RealmLevel.QI_REFINING_1: {"name": "练气期一层", "max_qi": 100, "qi_per_sec": 1.0},
	RealmLevel.QI_REFINING_2: {"name": "练气期二层", "max_qi": 200, "qi_per_sec": 1.2},
	RealmLevel.QI_REFINING_3: {"name": "练气期三层", "max_qi": 350, "qi_per_sec": 1.4},
	RealmLevel.QI_REFINING_4: {"name": "练气期四层", "max_qi": 550, "qi_per_sec": 1.6},
	RealmLevel.QI_REFINING_5: {"name": "练气期五层", "max_qi": 800, "qi_per_sec": 1.8},
	RealmLevel.QI_REFINING_6: {"name": "练气期六层", "max_qi": 1100, "qi_per_sec": 2.0},
	RealmLevel.QI_REFINING_7: {"name": "练气期七层", "max_qi": 1450, "qi_per_sec": 2.2},
	RealmLevel.QI_REFINING_8: {"name": "练气期八层", "max_qi": 1850, "qi_per_sec": 2.4},
	RealmLevel.QI_REFINING_9: {"name": "练气期九层", "max_qi": 2300, "qi_per_sec": 2.6},
	RealmLevel.QI_REFINING_10: {"name": "练气期十层", "max_qi": 2800, "qi_per_sec": 2.8},
	
	# 筑基期
	RealmLevel.FOUNDATION_1: {"name": "筑基期一层", "max_qi": 3500, "qi_per_sec": 3.2},
	RealmLevel.FOUNDATION_2: {"name": "筑基期二层", "max_qi": 4500, "qi_per_sec": 3.6},
	RealmLevel.FOUNDATION_3: {"name": "筑基期三层", "max_qi": 5800, "qi_per_sec": 4.0},
	RealmLevel.FOUNDATION_4: {"name": "筑基期四层", "max_qi": 7400, "qi_per_sec": 4.4},
	RealmLevel.FOUNDATION_5: {"name": "筑基期五层", "max_qi": 9300, "qi_per_sec": 4.8},
	RealmLevel.FOUNDATION_6: {"name": "筑基期六层", "max_qi": 11500, "qi_per_sec": 5.2},
	RealmLevel.FOUNDATION_7: {"name": "筑基期七层", "max_qi": 14000, "qi_per_sec": 5.6},
	RealmLevel.FOUNDATION_8: {"name": "筑基期八层", "max_qi": 16800, "qi_per_sec": 6.0},
	RealmLevel.FOUNDATION_9: {"name": "筑基期九层", "max_qi": 19900, "qi_per_sec": 6.4},
	RealmLevel.FOUNDATION_10: {"name": "筑基期十层", "max_qi": 23300, "qi_per_sec": 6.8},
	
	# 结丹期
	RealmLevel.GOLDEN_CORE_1: {"name": "结丹期一层", "max_qi": 28000, "qi_per_sec": 7.5},
	RealmLevel.GOLDEN_CORE_2: {"name": "结丹期二层", "max_qi": 34000, "qi_per_sec": 8.5},
	RealmLevel.GOLDEN_CORE_3: {"name": "结丹期三层", "max_qi": 41000, "qi_per_sec": 9.5},
	RealmLevel.GOLDEN_CORE_4: {"name": "结丹期四层", "max_qi": 49000, "qi_per_sec": 10.5},
	RealmLevel.GOLDEN_CORE_5: {"name": "结丹期五层", "max_qi": 58000, "qi_per_sec": 11.5},
	RealmLevel.GOLDEN_CORE_6: {"name": "结丹期六层", "max_qi": 68000, "qi_per_sec": 12.5},
	RealmLevel.GOLDEN_CORE_7: {"name": "结丹期七层", "max_qi": 79000, "qi_per_sec": 13.5},
	RealmLevel.GOLDEN_CORE_8: {"name": "结丹期八层", "max_qi": 91000, "qi_per_sec": 14.5},
	RealmLevel.GOLDEN_CORE_9: {"name": "结丹期九层", "max_qi": 104000, "qi_per_sec": 15.5},
	RealmLevel.GOLDEN_CORE_10: {"name": "结丹期十层", "max_qi": 118000, "qi_per_sec": 16.5},
	
	# 元婴期
	RealmLevel.NASCENT_SOUL_1: {"name": "元婴期一层", "max_qi": 135000, "qi_per_sec": 18.0},
	RealmLevel.NASCENT_SOUL_2: {"name": "元婴期二层", "max_qi": 155000, "qi_per_sec": 20.0},
	RealmLevel.NASCENT_SOUL_3: {"name": "元婴期三层", "max_qi": 178000, "qi_per_sec": 22.0},
	RealmLevel.NASCENT_SOUL_4: {"name": "元婴期四层", "max_qi": 204000, "qi_per_sec": 24.0},
	RealmLevel.NASCENT_SOUL_5: {"name": "元婴期五层", "max_qi": 233000, "qi_per_sec": 26.0},
	RealmLevel.NASCENT_SOUL_6: {"name": "元婴期六层", "max_qi": 265000, "qi_per_sec": 28.0},
	RealmLevel.NASCENT_SOUL_7: {"name": "元婴期七层", "max_qi": 300000, "qi_per_sec": 30.0},
	RealmLevel.NASCENT_SOUL_8: {"name": "元婴期八层", "max_qi": 338000, "qi_per_sec": 32.0},
	RealmLevel.NASCENT_SOUL_9: {"name": "元婴期九层", "max_qi": 379000, "qi_per_sec": 34.0},
	RealmLevel.NASCENT_SOUL_10: {"name": "元婴期十层", "max_qi": 423000, "qi_per_sec": 36.0},
	
	# 化神期
	RealmLevel.SPIRIT_TRANSFORMATION_1: {"name": "化神期一层", "max_qi": 475000, "qi_per_sec": 40.0},
	RealmLevel.SPIRIT_TRANSFORMATION_2: {"name": "化神期二层", "max_qi": 535000, "qi_per_sec": 45.0},
	RealmLevel.SPIRIT_TRANSFORMATION_3: {"name": "化神期三层", "max_qi": 603000, "qi_per_sec": 50.0},
	RealmLevel.SPIRIT_TRANSFORMATION_4: {"name": "化神期四层", "max_qi": 679000, "qi_per_sec": 55.0},
	RealmLevel.SPIRIT_TRANSFORMATION_5: {"name": "化神期五层", "max_qi": 763000, "qi_per_sec": 60.0},
	RealmLevel.SPIRIT_TRANSFORMATION_6: {"name": "化神期六层", "max_qi": 855000, "qi_per_sec": 65.0},
	RealmLevel.SPIRIT_TRANSFORMATION_7: {"name": "化神期七层", "max_qi": 955000, "qi_per_sec": 70.0},
	RealmLevel.SPIRIT_TRANSFORMATION_8: {"name": "化神期八层", "max_qi": 1063000, "qi_per_sec": 75.0},
	RealmLevel.SPIRIT_TRANSFORMATION_9: {"name": "化神期九层", "max_qi": 1179000, "qi_per_sec": 80.0},
	RealmLevel.SPIRIT_TRANSFORMATION_10: {"name": "化神期十层", "max_qi": 1303000, "qi_per_sec": 85.0},
	
	# 炼虚期
	RealmLevel.VOID_REFINEMENT_1: {"name": "炼虚期一层", "max_qi": 1440000, "qi_per_sec": 95.0},
	RealmLevel.VOID_REFINEMENT_2: {"name": "炼虚期二层", "max_qi": 1590000, "qi_per_sec": 105.0},
	RealmLevel.VOID_REFINEMENT_3: {"name": "炼虚期三层", "max_qi": 1753000, "qi_per_sec": 115.0},
	RealmLevel.VOID_REFINEMENT_4: {"name": "炼虚期四层", "max_qi": 1929000, "qi_per_sec": 125.0},
	RealmLevel.VOID_REFINEMENT_5: {"name": "炼虚期五层", "max_qi": 2118000, "qi_per_sec": 135.0},
	RealmLevel.VOID_REFINEMENT_6: {"name": "炼虚期六层", "max_qi": 2320000, "qi_per_sec": 145.0},
	RealmLevel.VOID_REFINEMENT_7: {"name": "炼虚期七层", "max_qi": 2535000, "qi_per_sec": 155.0},
	RealmLevel.VOID_REFINEMENT_8: {"name": "炼虚期八层", "max_qi": 2763000, "qi_per_sec": 165.0},
	RealmLevel.VOID_REFINEMENT_9: {"name": "炼虚期九层", "max_qi": 3004000, "qi_per_sec": 175.0},
	RealmLevel.VOID_REFINEMENT_10: {"name": "炼虚期十层", "max_qi": 3258000, "qi_per_sec": 185.0},
	
	# 合体期
	RealmLevel.BODY_INTEGRATION_1: {"name": "合体期一层", "max_qi": 3530000, "qi_per_sec": 200.0},
	RealmLevel.BODY_INTEGRATION_2: {"name": "合体期二层", "max_qi": 3820000, "qi_per_sec": 220.0},
	RealmLevel.BODY_INTEGRATION_3: {"name": "合体期三层", "max_qi": 4128000, "qi_per_sec": 240.0},
	RealmLevel.BODY_INTEGRATION_4: {"name": "合体期四层", "max_qi": 4454000, "qi_per_sec": 260.0},
	RealmLevel.BODY_INTEGRATION_5: {"name": "合体期五层", "max_qi": 4798000, "qi_per_sec": 280.0},
	RealmLevel.BODY_INTEGRATION_6: {"name": "合体期六层", "max_qi": 5160000, "qi_per_sec": 300.0},
	RealmLevel.BODY_INTEGRATION_7: {"name": "合体期七层", "max_qi": 5540000, "qi_per_sec": 320.0},
	RealmLevel.BODY_INTEGRATION_8: {"name": "合体期八层", "max_qi": 5938000, "qi_per_sec": 340.0},
	RealmLevel.BODY_INTEGRATION_9: {"name": "合体期九层", "max_qi": 6354000, "qi_per_sec": 360.0},
	RealmLevel.BODY_INTEGRATION_10: {"name": "合体期十层", "max_qi": 6788000, "qi_per_sec": 380.0},
	
	# 大乘期
	RealmLevel.MAHAYANA_1: {"name": "大乘期一层", "max_qi": 7245000, "qi_per_sec": 410.0},
	RealmLevel.MAHAYANA_2: {"name": "大乘期二层", "max_qi": 7725000, "qi_per_sec": 450.0},
	RealmLevel.MAHAYANA_3: {"name": "大乘期三层", "max_qi": 8228000, "qi_per_sec": 490.0},
	RealmLevel.MAHAYANA_4: {"name": "大乘期四层", "max_qi": 8754000, "qi_per_sec": 530.0},
	RealmLevel.MAHAYANA_5: {"name": "大乘期五层", "max_qi": 9303000, "qi_per_sec": 570.0},
	RealmLevel.MAHAYANA_6: {"name": "大乘期六层", "max_qi": 9875000, "qi_per_sec": 610.0},
	RealmLevel.MAHAYANA_7: {"name": "大乘期七层", "max_qi": 10470000, "qi_per_sec": 650.0},
	RealmLevel.MAHAYANA_8: {"name": "大乘期八层", "max_qi": 11088000, "qi_per_sec": 690.0},
	RealmLevel.MAHAYANA_9: {"name": "大乘期九层", "max_qi": 11729000, "qi_per_sec": 730.0},
	RealmLevel.MAHAYANA_10: {"name": "大乘期十层", "max_qi": 12393000, "qi_per_sec": 770.0},
	
	# 飞升
	RealmLevel.ASCENSION: {"name": "飞升", "max_qi": 999999999, "qi_per_sec": 1000.0}
}

# 当前境界
var current_realm: RealmLevel = RealmLevel.QI_REFINING_1

# 获取境界名称
func get_realm_name() -> String:
	return REALM_CONFIG[current_realm]["name"]

# 获取最大灵气值
func get_max_qi() -> int:
	return REALM_CONFIG[current_realm]["max_qi"]

# 获取基础灵气/秒
func get_base_qi_per_sec() -> float:
	return REALM_CONFIG[current_realm]["qi_per_sec"]

# 是否可以突破
func can_breakthrough() -> bool:
	return current_realm < RealmLevel.ASCENSION

# 突破到下一境界
func breakthrough() -> bool:
	if can_breakthrough():
		current_realm = (current_realm + 1) as RealmLevel
		return true
	return false

# 获取当前境界索引
func get_realm_index() -> int:
	return current_realm
